package com.demo.crm.springboot3security.entity;

import java.time.LocalDateTime;

import org.apache.ibatis.type.JdbcType;

import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.RelationManyToOne;
import com.mybatisflex.annotation.Table;

import lombok.Data;

/**
 * 表单数据实体
 */
@Data
@Table("form_data")
public class FormData {
    @Id(keyType = KeyType.Auto)
    private Long id;

    @Column("form_id")
    private Long formId;

    @RelationManyToOne(selfField = "form_id", targetField = "id")
    private CustomForm form;

    @Column(value = "data", jdbcType = JdbcType.BLOB)
    private String data;

    @Column
    private Long createdBy;        // 创建人ID

    @Column
    private Long updatedBy;        // 更新人ID

    private String status;         // 数据状态

    @Column
    private Long parentId;         // 父记录ID（用于处理关联数据）

    @Column
    private String metadata;       // 元数据（JSON格式，用于存储额外信息）

    private Integer version;       // 版本号，用于乐观锁

    private LocalDateTime createdAt;

    private LocalDateTime updatedAt;

    public void prePersist() {
        createdAt = LocalDateTime.now();
        updatedAt = LocalDateTime.now();
    }

    public void preUpdate() {
        updatedAt = LocalDateTime.now();
    }
} 